#include "Observer.h"
#include "Observable.h"
#include "Mediator.h"
#include "Message.h"
#include "MessageType.h"

#include <iostream>

void main()
{
	Mediator m;

	ObserverIfc *observer1 = new Observer("observer1");
	ObserverIfc *observer2 = new Observer("observer2");

	Observable observrable(&m);

	//first, send lvl 1 msg. we have no observers, so no one sould write it
	//to the screen.
	observrable.DoSomething(LVL1, "1. Hello World!");

	//observer 1 registers the lvl1 msgs.
	m.Register(observer1, LVL1);

	//now, we send a lvl2 message. again no one will observe it.
	observrable.DoSomething(LVL2, "2. Hello World!");

	//we send lvl1 msg, and now observer1 will get it and write it to the
	//screen.
	//output:
	//observer1: 3. Hello World
	observrable.DoSomething(LVL1, "3. Hello World!");

	//observer2 register to get lvl2 msgs.
	m.Register(observer2, LVL2);

	//we send lvl2 msg and observer 2 will get it.
	//output:
	//observer2: 4. Hello World
	observrable.DoSomething(LVL2, "4. Hello World!");

	//observer1 register to get lvl2 msgs
	m.Register(observer1, LVL2);

	//now both observers r registered to lvl2 msgs, and they both will print it.
	//notice that observer2 registered to lvl2 first, so in this case he will
	//write it first. on other applications, the recive order might change.
	//output:
	//observer2: 5. Hello World
	//observer1: 5. Hello World
	observrable.DoSomething(LVL2, "5. Hello World!");

	std::cin.get();
}